home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / dev / misc / ImageFXDevKit.lha / sdev / sas / examples / drawmodes / felt.c next >
Encoding:
C/C++ Source or Header  |  1993-07-26  |  3.7 KB  |  140 lines

  1. /*
  2.  * A Drawing Mode for ImageFX 1.5
  3.  *
  4.  * It works like this:
  5.  *
  6.  *    Find maximum of background R, G, B.
  7.  *    Subtract a tiny bit so we darken more each time we overwrite.
  8.  *    Adjust new R, G, B value by this percentage.
  9.  *    Store it.
  10.  *
  11.  *    (Kinda like a colorize.)
  12.  *
  13.  */
  14.  
  15. #include <exec/types.h>
  16. #include <scan/modall.h>
  17.  
  18. #define MAX(a,b)     ((a) > (b) ? (a) : (b))
  19.  
  20. /**********************************************************************\
  21.  
  22.                                 Library Vectors
  23.  
  24. \**********************************************************************/
  25.  
  26. int __asm DM_PutInit (void)
  27. {
  28.    return(1);
  29. }
  30.  
  31. void __asm DM_PutCleanup (void)
  32. {
  33. }
  34.  
  35. void __asm DM_PutColor (register __a0 short *destr,
  36.                         register __a1 short *destg,
  37.                         register __a2 short *destb,
  38.                         register __d0 LONG oldr,
  39.                         register __d1 LONG oldg,
  40.                         register __d2 LONG oldb,
  41.                         register __d3 LONG newr,
  42.                         register __d4 LONG newg,
  43.                         register __d5 LONG newb,
  44.                         register __d6 LONG x,
  45.                         register __d7 LONG y)
  46. {
  47.    LONG v;
  48.  
  49.    v = MAX(MAX(oldr,oldg),oldb) - 10;
  50.    if (v < 0) v = 0;
  51.  
  52.    *destr = (newr * v) / 255;
  53.    *destg = (newg * v) / 255;
  54.    *destb = (newb * v) / 255;
  55. }
  56.  
  57. void __asm DM_PutGrey  (register __a0 short *destg,
  58.                         register __d0 LONG oldg,
  59.                         register __d1 LONG newg,
  60.                         register __d6 LONG x,
  61.                         register __d7 LONG y)
  62. {
  63.    *destg = (newg * (oldg-10)) / 255;
  64. }
  65.  
  66. /*
  67.  * You cannot rely on this being called after DM_PutInit(), or
  68.  * vice versa.
  69.  *
  70.  */
  71. void __asm DM_NewPoint (register __d0 int n,
  72.                         register __d1 int total,
  73.                         register __d2 int x,
  74.                         register __d3 int y,
  75.                         register __d4 int z)
  76. {
  77.    /* This is called at every point along a user-drawn curve. */
  78. }
  79.  
  80. /**********************************************************************\
  81.  
  82.                          Library Initialization Stuff
  83.  
  84. \**********************************************************************/
  85.  
  86. /*
  87.  * This is the table of all the functions that can be called in this
  88.  * module.  The first four (Open, Close, Expunge, and Null) are reserved
  89.  * for system use and MUST be specified in the order shown.  The actual
  90.  * functions are in the standard module startup code.
  91.  */
  92. ULONG FuncTable[] = {
  93.    /* These four MUST be present in this order */
  94.    (ULONG) LibOpen,
  95.    (ULONG) LibClose,
  96.    (ULONG) LibExpunge,
  97.    (ULONG) LibNull,
  98.  
  99.    /* Specific to the module */
  100.    (ULONG) DM_PutInit,
  101.    (ULONG) DM_PutCleanup,
  102.    (ULONG) DM_PutColor,
  103.    (ULONG) DM_PutGrey,
  104.    (ULONG) DM_NewPoint,
  105.  
  106.    /* End with -1L */
  107.    (ULONG) -1L
  108. };
  109.  
  110. /*
  111.  * These are used by the standard module startup code.
  112.  * LibraryName is the name of the library, and LibraryID is a short
  113.  * description of the library.  Both of these are largely irrelavent,
  114.  * but they are included just for completeness.
  115.  */
  116. UBYTE LibraryID[]    = "$VER: Felt Tip Drawing Mode 1.04.21 (12.6.93)";
  117. UBYTE LibraryType    = NT_DRAWMODE;
  118.  
  119. /*
  120.  * This is called by the standard module startup code when Image Scan
  121.  * first opens the module.  Here we should fill in the NumGads,
  122.  * NewGad, Language, and LangCount fields of the provided ModuleBase
  123.  * structure if necessary.
  124.  */
  125. long  __asm UserOpen (register __a6 struct ModuleBase *modbase)
  126. {
  127.    return(TRUE);
  128. }
  129.  
  130. /*
  131.  * This is called by the standard module startup code when Image Scan
  132.  * closes the module.  It should cleanup anything allocated or obtained
  133.  * in the UserOpen() function.
  134.  */
  135. long  __asm UserClose (register __a6 struct ModuleBase *modbase)
  136. {
  137.    return(TRUE);
  138. }
  139.  
  140.